import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * 静态路由表
 * @type {({path: string, component: (function(): Promise<*>), hidden: boolean}|{path: string, component: (function(): Promise<*>), hidden: boolean}|{path: string, component: (function(): Promise<*>), hidden: boolean}|{path: string, component: (function(): Promise<*>), hidden: boolean}|{path: string, component: (function(): Promise<*>), hidden: boolean})[]}
 */
export const constantRoutes = [
  {
    // 登录页
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  }
]


/**
 * 动态路由表
 */
export const asyncRouterMap = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: { role: ['1', '2'] },
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      meta: { title: '主页', icon: 'el-icon-s-home', role: ['1', '2', '3',  '4'] },
      component: () => import('@/views/dashboard/index')
    }]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/index',
    meta: { title: '人员管理', icon: 'manage', role: ['1'] },
    children: [{
      path: 'index',
      name: 'Student',
      meta: { title: '学生管理', icon: 'user', role: ['1'] },
      component: () => import('@/views/user/student')
    },{
      path: 'admin',
      name: 'Admin',
      meta: { title: '管理员管理', icon: 'user', role: ['1'] },
      component: () => import('@/views/user/index')
    }]
  },
  {
    path: '/active',
    component: Layout,
    redirect: '/index',
    meta: { title: '活动管理', icon: 'manage', role: ['1'] },
    children: [{
      path: 'index',
      name: 'Index',
      meta: { title: '活动列表', icon: 'el-icon-s-order', role: ['1'] },
      component: () => import('@/views/active/index')
    },{
      path: 'history',
      name: 'History',
      meta: { title: '活动报名', icon: 'el-icon-s-order', role: ['1'] },
      component: () => import('@/views/active/history')
    }]
  },
  {
    path: '/lost',
    component: Layout,
    redirect: '/index',
    meta: { title: '失物招领管理', icon: 'manage', role: ['1'] },
    children: [{
      path: 'index',
      name: 'Index',
      meta: { title: '失物招领列表', icon: 'el-icon-s-order', role: ['1'] },
      component: () => import('@/views/lostFound/index')
    }]
  },
  {
    path: '/health',
    component: Layout,
    redirect: '/index',
    meta: { title: '健康填报', icon: 'manage', role: ['1'] },
    children: [{
      path: 'city',
      name: 'City',
      meta: { title: '跨市填报', icon: 'el-icon-s-order', role: ['1'] },
      component: () => import('@/views/health/city')
    },{
      path: 'index',
      name: 'Index',
      meta: { title: '健康填报', icon: 'el-icon-s-claim', role: ['1'] },
      component: () => import('@/views/health/index')
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', name: '404', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
